import vue from 'vue'
import toastComponent from './toastComponent.vue'

// //使用vue的extend，以vue文件为基础组件，返回一个可以创建vue组件的特殊构造函数

const confirm = {
    install(Vue) {
        const ToastConstructor = vue.extend(toastComponent);
        const toastDom = new ToastConstructor({
            el: document.createElement('div'),
            data() {
                return {
                    text: 'text',
                    show: false
                }
            }
        })
        document.body.appendChild(toastDom.$el);
        const theConfirm = function (text, show = false, duration = 2000) {
            toastDom.show = show
            toastDom.text = text + "打开次数" 
         console.log(Vue)
            return new Promise((res, rej) => {
                toastDom.ok = function () {
                    res()
                    toastDom.show = false

                }
                toastDom.esc = function () {
                    rej()
                    toastDom.show = false
                }
            })
        }
        Vue.prototype.confirm = function (text) {
            return theConfirm(text, true)
        }
    },
    count: 0

}
export default confirm